<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$merchid=$this->checklogin();
if($_RQ['op']=='list'){	
	$params=array('merchid'=>$merchid,'gtype'=>4,'ispay'=>1,'uniacid'=>$_SESSION['uniacid']);	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	if(isset($_RQ['id'])){
		$params['id']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$total='';
	$fields='';
	$list=pdo_getslice('jy_merch_mgoodslog',$params,array($pindex,$psize),$total,$fields,'','id desc');
    foreach($list as &$item){
       $item['tabletitle']=pdo_getcolumn('jy_weishop_table',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['tableid']),'title');
       $item['czuser'] = '管理员';
    }
	if($list){
		//创建时间
		$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']);	
		if($_RQ['createtime']){
			$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
			$time_range=json_decode($time_range,true);
			$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
			$return['params']['createtime']=$time_range;
		}
		
	}

	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'gtitle','title'=>'名称','type'=>'string'),
			array('name'=>'gimage','title'=>'图片','type'=>'image'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'gprice','title'=>'抹零金额','type'=>'string'),
			array('name'=>'tabletitle','title'=>'桌台','type'=>'string'),
			array('name'=>'createtime','title'=>'操作时间','type'=>'time'),
			array('name'=>'czuser','title'=>'操作员','type'=>'string'),
		)),
		'search'=>array(
		                                                   
			array('type'=>'choose','width'=>15,'action'=>'jy_merch/order.get_tables/','name'=>'id','title'=>'选择桌台'),
			array('name'=>'createtime','width'=>15,'title'=>'操作时间','type'=>'time_range'),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('merchid'=>$merchid,'gtype'=>4,'ispay'=>1,'uniacid'=>$_SESSION['uniacid']);
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('jy_merch_mgoodslog',$params);
    foreach($list as &$item){
       $item['tabletitle']=pdo_getcolumn('jy_weishop_table',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['tableid']),'title');
       $item['createtime'] = date('Y-m-d H:i:s',$item['createtime']);
    }
	$header=array(
		'title'=>'商品名称',
		'ordersn'=>'订单号',
		'gprice'=>'抹零金额',
		'createtime'=>'操作时间',
		'tabletitle'=>'桌台'
	);
	cfc('tools')->export2excel($header,$list,'抹零数据统计'.date('YmdHis').rand(1,999));
}

